Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = binding.value
  }
});

Vue.directive('scroll-load', {
  bind: function (el, binding, vnode) {
    let that = vnode.context,
      isFirst = true;

    that.$refs[vnode.data.ref].$refs.bodyWrapper.onscroll = ()=> {
      let tableScrollHeight = that.$refs[vnode.data.ref].$refs.bodyWrapper.scrollHeight,
        tableScrollTop = that.$refs[vnode.data.ref].$refs.bodyWrapper.scrollTop,
        tableHeight = that.$refs[vnode.data.ref].$refs.bodyWrapper.offsetHeight;

      if (isFirst && (tableScrollHeight - tableScrollTop < tableHeight + 20)) {
        isFirst = false;
        binding.value();
      }
      if (tableScrollHeight - tableScrollTop >= tableHeight + 20) {
        isFirst = true;
      }
    }
  }
});
